package com.timedomain.him.remake.utils;

import android.app.ProgressDialog;
import android.content.Context;
import android.os.Handler;
import com.timedomain.him.remake.ui.SettingActivity;

import java.io.FileNotFoundException;
import java.io.PrintStream;

public class RunUtils {


    public static void runProgressDialog(Context ctx,String message,Runnable r){
        final ProgressDialog progressDialog = ProgressDialog.show(ctx,null,message,true);
        Handler hWnd = new android.os.Handler();
        progressDialog.setCancelable(false);
        new Thread(() -> {
            try {
                r.run();
            } catch (Exception e) {
                hWnd.post(progressDialog::dismiss);
                e.printStackTrace();
            }
            hWnd.post(progressDialog::dismiss);
        }).start();
    }

    public static void runLongWorkOnUIThread(Runnable r){
        Thread t =new Thread(r);
        t.start();
        try {
            t.join();
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }
}
